package com.zheng.business.web.controller.task;

import com.zheng.business.common.constant.BusinessConstant;
import com.zheng.business.web.service.BusinessAgentHttpTaskService;
import com.zheng.common.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lvg EMIAL：<a href="mailto:weiguo.liang@gh-ca.com">weiguo.liang@gh-ca.com</a> <br>
 * @version 1.0 <br>
 * @Company: GH-CA<br>
 * @ClassName: BusinessHttpTaskController <br>
 * @Description: TODO <br>
 * @date 2019/8/8 11:52<br>
 **/
@RestController
@RequestMapping("/task/agent")
@Api(value = "代理任务调度控制器", description = "代理任务调度控制器")
public class BusinessAgentHttpTaskController  extends BaseController {

    @Autowired
    BusinessAgentHttpTaskService businessAgentHttpTaskService;
    /**
     * 每天凌晨 3点运行统计 统计前一天的代理金额
     * @param request
     * @return
     */
    @ApiOperation(value = "代理金额日统计任务")
    @RequestMapping(value = "/dayAmount", method = {RequestMethod.POST})
    public Object amount( HttpServletRequest request) {

        // request.getParameter("d"); //日期字符串 如： 2018-01-01
        return businessAgentHttpTaskService.statisticsAgentAmountByDateTypeAndDate(
                request.getParameter("d") , BusinessConstant.StatisticsDateType.DAY
        );
    }

    /**
     * 每月1号凌晨 3点运行统计
     * @param request
     * @return
     */
    @ApiOperation(value = "代理金额月统计任务")
    @RequestMapping(value = "/monthAmount", method = {RequestMethod.POST})
    public Object monthAmount( HttpServletRequest request) {
        // request.getParameter("d"); //日期字符串 如： 2018-01
        return businessAgentHttpTaskService.statisticsAgentAmountByDateTypeAndDate(
                request.getParameter("d") , BusinessConstant.StatisticsDateType.MONTH
        );
    }

    /**
     * 每年 1月1号 凌晨 3点运行统计
     * @param request
     * @return
     */
    @ApiOperation(value = "代理金额年统计任务")
    @RequestMapping(value = "/yearAmount", method = {RequestMethod.POST})
    public Object yearAmount( HttpServletRequest request) {
        // request.getParameter("d"); //日期字符串 如： 2018
        return businessAgentHttpTaskService.statisticsAgentAmountByDateTypeAndDate(
                request.getParameter("d") , BusinessConstant.StatisticsDateType.YEAR
        );
    }


    /**
     * 每月1号凌晨 3点运行统计
     * @param request
     * @return
     */
    @ApiOperation(value = "代理账单月统计任务")
    @RequestMapping(value = "/bill", method = {RequestMethod.POST})
    public Object bill( HttpServletRequest request) {
        // request.getParameter("d"); //日期字符串 如： 2018-01
        return businessAgentHttpTaskService.statisticsAgentAmountBill(
                request.getParameter("d")
        );
    }

}
